﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevDL.UserLimit.Models;
using DevDL.UserLimit.IDAL;
using System.Data;
using System.Data.SqlClient;
using DevDL.UserLimit.DBUtility;

namespace DevDL.UserLimit.SQLServerDAL
{
    public class UserInfoDAL : IUserInfoDAL
    {
        public UserInfo GetUserInfoByUserId(string userId)
        {
            UserInfo userInfo = null;
            string sql = "SELECT [Id],[LoginId],[LoginPwd],[State],[DeptId],[PositionId] FROM T_UserInfo WHERE LoginId=@LoginId";
            SqlParameter par = new SqlParameter("@LoginId", userId);
            try
            {
                using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.GetConnSting(), CommandType.Text, sql, par))
                {
                    if (reader.Read())
                    {
                        userInfo = new UserInfo();
                        userInfo.Id = reader["Id"].ToString();
                        userInfo.LoginId = reader["LoginId"].ToString();
                        userInfo.LoginPwd = reader["LoginPwd"].ToString();
                        userInfo.State = Convert.ToInt32(reader["State"]);
                        userInfo.DeptId = Convert.ToInt32(reader["DeptId"]);
                        userInfo.PositinId = Convert.ToInt32(reader["PositionId"]);
                    }
                    return userInfo;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
